#pragma once
#include "Box2DManager.h"
#include "RobotPart.h"
#include <map>
#include "tinyxml2/tinyxml2.h"

class RobotPartBase;
class Robot
{
	friend class RobotManager;
private:
	Robot();
public:
	~Robot();

	void Reset();

	void Clear();

	void Inverse();

	void SetCommand(RobotCommandState c);

	// update
	void OnUpdate(float frameTime);

	// render
	void OnPreRender();

	void Initialize();

	bool LoadParts(tinyxml2::XMLElement * robot_node, bool reverse);

	void RemovePart(uint part_id);
	
	float2 GetCorePosition();

	void SetCorePosition(const float2& cp);

	void SetActive(bool flag);

	void AddPartDef(const PartCreateInfo& info);

	void AddJointsDef(const JointCreateInfo& info);

	void CreateParts();

	void CreateJoints();

	void SaveAttribute(tinyxml2::XMLDocument& doc, tinyxml2::XMLNode* robot_node);

private:

	std::map<uint, std::shared_ptr<RobotPartBase>>			m_RobotPartMap;

	std::shared_ptr<RobotPartBase>							m_RobotCore;

	RobotCommandState										m_CurentCommand;

	bool													m_Inverse;

	float2													m_CorePosition;

	std::vector<PartCreateInfo>								m_PartCreateVec;

	std::vector<JointCreateInfo>							m_JointCreateVec;
public:
	uint													uid;
};